/**
 *****************************************************************************
 * @file
 * @brief
 * @author taoye
 * @version V0.0.1
 * @date 2021/08/24
 ****************************************************************************
 */
 
#ifndef __DRV_SPI_SOFT_H
#define __DRV_SPI_SOFT_H

#include "drv_include.h"
#include "drv_f4_gpio.h"
#include "A_shell.h"
/* private config -----------------------------------------------------------*/
typedef struct
{
    drv_gpio_t      cs;
    drv_gpio_t      sck;
    drv_gpio_t      miso;
    drv_gpio_t      mosi;

    SPI_TypeDef*    SPIx;
}spi_private_t;

/* Public defines -----------------------------------------------------------*/
typedef struct drv_spi drv_spi_t;

/* Public enum    -----------------------------------------------------------*/

typedef enum
{
    SPI_SPEED_HIGH,
    SPI_SPEED_MEDIUM,
    SPI_SPEED_SLOW,
}spi_speed_e;

typedef enum
{
    SPI_CS_NULL,
    SPI_CS_EN_H,
    SPI_CS_EN_L,
}spi_cs_e;

typedef enum
{
    SPI_MSB,
    SPI_LSB,
}spi_order_e;

typedef enum
{
    SPI_CPOL_H,
    SPI_CPOL_L,
}spi_cpol_e;

typedef enum
{
    SPI_CPHA_1,
    SPI_CPHA_2,
}spi_cpha_e;

typedef enum
{
    SPI_TRANS_BYTE      = 8,
    SPI_TRANS_HALFWORD  = 16,
    SPI_TRANS_THREEBYTE = 24,
    SPI_TRANS_WORD      = 32,
}spi_trans_e;

/* Public Struct  -----------------------------------------------------------*/
struct drv_spi
{
    /* ***************Public Parameter  *************** */
    const char *    DRV;
    const char *    PIN_CS;
    const char *    PIN_SCK;
    const char *    PIN_MISO;
    const char *    PIN_MOSI;
    
    spi_speed_e     SPEED;
    spi_cpol_e      CPOL;
    spi_cpha_e      CPHA;
    spi_cs_e        CS_EN;
    spi_order_e     ORDER;
    spi_trans_e     TRANS;
    uint32_t        CS_DELAY_US;

    /* ***************Public Method     *************** */
    void ( *ReadWrite )( drv_spi_t *, void *, void *, uint32_t );

    /* ***************Private Attributes*************** */
    spi_private_t private;
};


/* Public Variable  ---------------------------------------------------------*/
//Pointer

//Array

//Const

/* Pubilc function prototypes -----------------------------------------------*/
int Drv_Spi_Init( drv_spi_t * this );

#endif

